package cn.dai;

import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * @author ArkD42
 * @file 1 - Java基础语法
 * @create 2020 - 06 - 01 - 11:02
 */
public class URLCodeTest {

    @Test
    public void encoding() throws UnsupportedEncodingException {
        String text = "这是一段演示文本";

        String encode = URLEncoder.encode(text, "utf-8");

        System.out.println(encode);
    }

    @Test
    public void decoding() throws UnsupportedEncodingException {
        String urlCode = "%E8%BF%99%E6%98%AF%E4%B8%80%E6%AE%B5%E6%BC%94%E7%A4%BA%E6%96%87%E6%9C%AC";

        String decode = URLDecoder.decode(urlCode, "utf-8");

        System.out.println(decode);
    }

}
